package gui.Main;

import java.net.InetAddress;
import proxyCommand.*;

/**
 * HyPeerWeb is on the default port
 * 
 * All GUIs are on port hypeerweb.port+1
 *
 */

public class GUIClientServer {

	public static void main(String[] args) {
		System.out.println("Starting");
		GlobalObjectId globalObjectId=null;
		try {
			globalObjectId = new GlobalObjectId(args[0],
								new PortNumber(Integer.parseInt(args[1])), 
								new LocalObjectId(Integer.parseInt(args[2])));
			HyPeerWebProxy hp = HyPeerWebProxy.getSingleton(globalObjectId);
			
			GlobalObjectId thisGlobalObjectId = new GlobalObjectId(InetAddress.getLocalHost().getHostAddress(),
					new PortNumber(Integer.parseInt(args[3])),
					new LocalObjectId());
			//store the gui into the objectDB 
			ObjectDB curDB=ObjectDB.getSingleton();
			curDB.store(thisGlobalObjectId.getLocalObjectId(), (Object)GUI.getSingleton(hp, thisGlobalObjectId));
			
			PeerCommunicator.createPeerCommunicator(thisGlobalObjectId.getPortNumber());
			hp.connectToGUI(thisGlobalObjectId);
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		System.out.println("Finishing");
	}
}
